//
//  OGLmap.h
//  CommandCenter08
//
//  Created by Matt Roman on 7/3/08.
//  Copyright 2008 University of Oklahoma. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <OpenGL/gl.h>
#import <OpenGL/glext.h>
#import <OpenGL/glu.h>
#import "Waypoint.h"
#import "Rover.h"
#import "definitions.h"

typedef	struct _eye {
	Point3D viewPosition;
	Vector3D viewDirection;
	Vector3D viewUp;
	Point3D rotateCenter;
	GLdouble aperture;
	GLint viewWidth, viewHeight;
} eye;

@interface OGLmap : NSOpenGLView {
	NSMutableArray		*WPList;
	IBOutlet NSButton	*gridButton;
	IBOutlet NSButton	*mapButton;
	IBOutlet NSButton	*waypointButton;
	IBOutlet NSButton	*waypointNumButton;
	IBOutlet NSTextField	*mapScale;
	IBOutlet NSTextField	*cursorPosition;
	IBOutlet NSPanel	*mapCalibrationPanel;
	
	Rover				*bot;
	Point3D				*botPos;
	eye					camera;
	int					camView;
	NSPoint				mousePoint;
	NSTimer				*timer;
	int					gridStep;
	GLuint				botTexture,mapTexture,base;
	NSInteger			mapWidth,mapHeight;
	NSInteger			scaledMapWidth,scaledMapHeight;
	GLfloat				botWidth,botHeight;
	Point3D				mapOrigin;
	double				WorldRadius;
	double				Xres,Yres;
	NSString			*mapName;
	
	// map Calibration panel
	BOOL					calibrated;
	IBOutlet NSTextField	*latDegreesField;
	IBOutlet NSTextField	*lonDegreesField;
	IBOutlet NSTextField	*indicatorField;
	LatLonCoord				calPoint[2];
	Point3D				calPointPixel[2];
	LatLonCoord				homePoint;
}

+ (NSOpenGLPixelFormat*) basicPixelFormat;
- (id) initWithFrame: (NSRect) frameRect andRover:(Rover*)robot;
- (void)initCamera;
- (void)updateCamera;
- (void)updateProjection;
- (void)initMapTexture:(NSBitmapImageRep*)bitmap;
- (void)initBotTexture;
- (void)buildFont;
- (void)glPrint:(NSString *)fmt, ...;

- (void)overlayFrame;
- (void)drawFrame;
- (void)drawRect:(NSRect)bounds;
- (void)setWPList:(NSMutableArray *)array;
- (Point3D)mapOrigin;
- (void)setWorldRadius:(double)wr;
- (void)setMapName:(NSString*)name;
- (NSString *)mapName;
- (double)Xres;
- (double)Yres;
- (void)setHomePoint:(LatLonCoord)h;

- (BOOL)calibrated;
-(void)calibrateMap;
-(IBAction)setCalibrateButton:(id)sender;
- (void)calibrationFromFile:(double)xpar and:(double)ypar origin:(Point3D)org;
- (Point3D)LatLonCoordsFrom:(LatLonCoord)ll1 to:(LatLonCoord)ll2;
- (Point3D)getCrosshairPosition;
@end
